package cn.ad.param;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class AdTemplateQuery extends AbstractPagingSortParam{
	
	//模版ID或者名称
	private String search;
	//供应商ID
	private String supplierId;
	//平台ID
	private String platformId;
	


	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}
	


	public String getSupplierId() {
		return supplierId;
	}

	public void setSupplierId(String supplierId) {
		this.supplierId = supplierId;
	}

	public String getPlatformId() {
		return platformId;
	}

	public void setPlatformId(String platformId) {
		this.platformId = platformId;
	}

	public Map<String,Object> getSearchMap(){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("search", this.search);
		if(!isNull(this.supplierId)) {
			map.put("supplierId", this.supplierId);
		}
		if(!isNull(this.platformId)) {
			map.put("platformId", this.platformId);
		}
		map.put("sortby", this.getSortby());
		map.put("order", this.getOrder());
		return map;
	}
	
	
	/**
	 * 默认按id排序
	 */
	@Override
	public String getSortby() {
		return StringUtils.isEmpty(super.getSortby()) ? "id" : super.getSortby();
	}

	/**
	 * 默认按降序排序
	 */
	@Override
	public ORDER getOrder() {
		return super.getOrder() == null ? ORDER.desc : super.getOrder();
	}
	/**
	 * 判断字符串是否为null
	 * @return
	 */
	private boolean isNull(String str) {
		if(null == str || "".equals(str) || str.length() == 0) {
			return true;
		}
		return false;
	}
}
